const exec = require('child_process').exec;
const path = require('path');

module.exports = {
    configureWebpack: config => {
        // 只在生产模式下添加混淆插件
        if (process.env.NODE_ENV === 'production') {
            config.plugins.push({
                apply: (compiler) => {
                    compiler.hooks.done.tap('AfterEmitPlugin', (compilation) => {
                        const batPath = path.resolve(__dirname, 'obfuscate.bat');
                        exec(batPath, { cwd: __dirname }, (err, stdout, stderr) => {
                            if (err) {
                                console.error(`Exec error: ${err}`);
                                return;
                            }
                            console.log(`Output: ${stdout}`);
                        });
                    });
                }
            });
        }
    }
};
